﻿using Ctyun.CF.SDK.Core;
using System.Text.Json;

namespace Ctyun.CF.SDK.Example;

internal class QueryWorkflowExample
{
    static void Main(string[] args)
    {
        string workflowId = "Your-workflow-id";

        CTApiClient client = new CTApiClient.Builder()
            .Endpoint("https://fc-global.ctapi.ctyun.cn") // 函数计算openapi域名 API endpoint，必填
            .Region("200000002368") // Region，必填，示例为：西南1
            .Ak("Your-AK")  // 天翼云AK，必填
            .Sk("Your-SK")  // 天翼云SK，必填
            .Build();

        var jsonString = client.Request("GET", "/openapi/v1/workflow" + workflowId, null, null);

        var options = new JsonSerializerOptions
        {
            PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
            DictionaryKeyPolicy = JsonNamingPolicy.CamelCase
        };

        var response = JsonSerializer.Deserialize<OpenapiResponse<Dictionary<string, object>>>(jsonString, options);
        if (response.StatusCode == 0)
        {
            Console.WriteLine($"Workflow name: {response.ReturnObj["name"]}, description: {response.ReturnObj["description"]}");
        }
        else
        {
            Console.WriteLine($"Request fail, statusCode: {response.StatusCode}, message: {response.Message}");
        }
    }
}
